package com.ruoyi.mq.consumer;

import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.utils.JsonUtil;
import com.ruoyi.system.api.RemoteLogService;
import com.ruoyi.system.api.domain.SysOperLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

/**
 * Kafaka消费端
 */
@Service
public class KafkaConsumer {

    @Autowired
    private RemoteLogService remoteLogService;

    @KafkaListener(topics = "log_queue", groupId = "zq-group")
    public void saveLog(String msg) throws Exception {
        SysOperLog sysOperLog = JsonUtil.jsonToBean(msg, SysOperLog.class);
        remoteLogService.saveLog(sysOperLog, SecurityConstants.INNER);
//        System.out.println("收到消息："+msg);
    }

}
